#include "common.h"
#include <pthread.h>

void *func(void *arg)
{
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);

	while(1)
	{
		usleep(5000);
		printf("before cancle\n");
		pthread_testcancel();
		//usleep(5000);
		printf("after cancle\n");
	}

	return NULL;
}

int main()
{
	pthread_t tid;
	int ret = 0;
	
	ret = pthread_create(&tid, NULL, func, NULL);
	if(ret != 0)
		err_sys("pthread_create error\n");

	sleep(2);
	pthread_cancel(tid);
	pthread_join(tid, NULL);
	return 0;
}
